package com.kfm.src;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 添加自增主键约束
 */
public class demo1 {
    public static void main(String[] args) {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
        // 获取连接
        String url = "jdbc:mysql://localhost:3306/company_info";
        String user = "root";
        String pass = "";
        Statement sta;
        try
        {
            Connection connection = DriverManager.getConnection(url, user, pass);
            sta = connection.createStatement();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        try {
            sta.executeUpdate("insert into dept_new (deptno,deptname)values (10,'外交部')",sta.getUpdateCount());
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        System.out.println("执行成功");


    }
}
